#include "mainscene.h"
#include "ui_mainscene.h"
#include <QPainter>
#include "mypushbutton.h"
#include <QDebug>
#include <QTimer>

MainScene::MainScene(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainScene)
{
    ui->setupUi(this);

    setFixedSize(1200,800);

    setWindowIcon((QIcon)":/pictures/title.png");

    setWindowTitle("主界面");

    MyPushButton * startBtn = new MyPushButton(":/pictures/startbutton.png");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.05,this->height()*0.75);

    MyPushButton * quitBtn = new MyPushButton(":/pictures/quitbutton.png");
    quitBtn->setParent(this);
    quitBtn->move(this->width()*0.90,this->height()*0.75);

    MyPushButton * helpBtn = new MyPushButton(":/pictures/helpbutton.png");
    helpBtn->setParent(this);
    helpBtn->move(this->width()*0.45,this->height()*0.05);

    ft = new First;
    ht = new help;
    fail = new Faliure;

    connect(fail,&Faliure::feb,this,[=](){
        fail->hide();
        this->show();
    });

    connect(ft,&First::ftb,this,[=](){
        ft->hide();
        this->show();
    });

    connect(ht,&help::hpb,this,[=](){
        ht->hide();
        this->show();
    });

    connect(startBtn,&MyPushButton::clicked,[=](){

        startBtn->zoom1();
        startBtn->zoom2();

        QTimer::singleShot(500,this,[=](){
            this->hide();
            ft->show();
    });
});

    connect(quitBtn,&MyPushButton::clicked,[=](){

        quitBtn->zoom1();
        quitBtn->zoom2();

        QTimer::singleShot(500,this,[=](){
           this->close();
    });
});

    connect(helpBtn,&MyPushButton::clicked,[=](){

        helpBtn->zoom1();
        helpBtn->zoom2();

        QTimer::singleShot(500,this,[=](){
           this->hide();
            ht->show();
    });
});
}

void MainScene::paintEvent(QPaintEvent *)
{
   QPainter painter(this);
   QPixmap pix;
   pix.load(":/pictures/mainscene.png");
   painter.drawPixmap(0,0,this->width(),this->height(),pix);
}

MainScene::~MainScene()
{
    delete ui;
}
